package com.fruit.dao.impl;

import com.fruit.dao.FruitDao;
import com.fruit.dao.base.BaseDAO;
import com.fruit.pojo.Fruit;

import java.util.List;

public class FruitDaoImpl extends BaseDAO<Fruit> implements FruitDao {
    @Override
    public List<Fruit> getFruitList() {
        String sql = "select * from t_fruit";
        return  super.executeQuery(sql);
    }
    @Override
    public boolean addFruit(Fruit fruit) {
        String sql = "insert into t_fruit values(0,?,?,?,?)";
        //成功放回1，错误直接抛出异常
        int count = super.executeUpdate(sql, fruit.getFname(), fruit.getPrice(),
                fruit.getFcount(), fruit.getRemark());
        return count>0;
    }
    @Override
    public boolean updateFruit(Fruit fruit) {
        String sql = "update t_fruit set fcount = ? where fid = ?";

        return super.executeUpdate(sql,
                fruit.getFcount(),fruit.getFid())>0;
    }

    @Override
    public Fruit getFruitByFname(String fname) {
        return null;
    }

    @Override
    public boolean delFruit(String fname) {
        return false;
    }
}
